package com.sreader.logic;

import java.io.Serializable;
import java.util.Locale;

import com.google.gwt.dev.shell.BrowserChannel.Value;
import com.sreader.logic.NombresCalculer.nombreType;
import com.sreader.sreader4j.Messages;
import com.sreader.sreader4j.PersonBean;


public class InterpretationLogic implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String interpretationNH;
	private String description;
	private String individumNames;
	private String individumFirstNames;
	private String individumBirthDateAsString;
	private Locale currentLocale;
	private PersonBean firstPerson;
	private PersonBean secondPerson;
	private Messages messages;

	
	/**
	 * create an instance of the Interpret
	 * @param firstnames the firstnames of the individum
	 * @param names the names of the individum
	 */
	public InterpretationLogic(String firstnames, String names,Locale currentLocale,String feuilleName){
		setIndividumFirstNames(firstnames);
		setIndividumNames(names);
		setCurrentLocale(currentLocale);
		setMessages(new Messages(feuilleName,currentLocale));
		interpretationNH = "";
		description = "";
	}
	
	public InterpretationLogic(Locale currentLocale, String feuilleName){
		setCurrentLocale(currentLocale);
		setMessages(new Messages(feuilleName,currentLocale));
		interpretationNH = "";
		description = "";
	}
	
	
	public Locale getCurrentLocale() {
		return currentLocale;
	}
	
	public void setCurrentLocale(Locale currentLocale) {
		this.currentLocale = currentLocale;
	}
	public Messages getMessages() {
		return messages;
	}
	public void setMessages(Messages messages) {
		this.messages = messages;
	}
	public String getIndividumNames() {
		return individumNames;
	}
	public void setIndividumNames(String individumNames) {
		this.individumNames = individumNames;
	}
	public String getIndividumFirstNames() {
		return individumFirstNames;
	}
	public void setIndividumFirstNames(String individumFirstNames) {
		this.individumFirstNames = individumFirstNames;
	}
	public String getIndividumBirthDateAsString() {
		return individumBirthDateAsString;
	}
	public void setIndividumBirthDateAsString(String individumBirthDateAsString) {
		this.individumBirthDateAsString = individumBirthDateAsString;
	}
	/**
	 * 
	 * @param valueType
	 * @return
	 * @throws Throwable 
	 */
	public String setDescription(NombresCalculer.nombreType valueType) throws Throwable{
		if (valueType == null){
			throw new Exception("This methode need the type of the item to be decribed");
		}
		final String  descriptionString = "Desc";
		String translationkey = valueType + descriptionString;
		return messages.getString(translationkey);
	}
	
	public PersonBean getFirstPerson() {
		return firstPerson;
	}

	public void setFirstPerson(PersonBean firstPerson) {
		this.firstPerson = firstPerson;
	}

	public PersonBean getSecondPerson() {
		return secondPerson;
	}

	public void setSecondPerson(PersonBean secondPerson) {
		this.secondPerson = secondPerson;
	}

	
	/**
	 * 
	 * @param valueNH
	 * @return
	 */
	public String interpretNH(int valueNH){

		switch (valueNH) {
		case 1:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+ this.messages.getString(nombreType.NH +"1");
		case 2:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"2");
		case 3:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"3");
		case 4:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"4");
		case 5:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"5");
		case 6:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"6");
		case 7:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"7");
		case 8:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"8");
		case 9:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"9");
		case 11:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"11");
		case 22:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NH +"22");
		default:
			break;
		}
		return interpretationNH;
	}
	/*
	 * 
	 */
	public String interpretNJP(int valueNJP){
		switch (valueNJP) {
		case 1:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+ this.messages.getString(nombreType.NJP +"1")
					+ getAutorAndSource(nombreType.NJP);
		case 2:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"2")
					+ getAutorAndSource(nombreType.NJP);
		case 3:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"3")
					+ getAutorAndSource(nombreType.NJP);
		case 4:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"4")
					+ getAutorAndSource(nombreType.NJP);
		case 5:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"5")
					+ getAutorAndSource(nombreType.NJP);
		case 6:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"6")
					+ getAutorAndSource(nombreType.NJP);
		case 7:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"7")
					+ getAutorAndSource(nombreType.NJP);
		case 8:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"8")
					+ getAutorAndSource(nombreType.NJP);
		case 9:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"9")
					+ getAutorAndSource(nombreType.NJP);
		case 11:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"11")
					+ getAutorAndSource(nombreType.NJP);
		case 22:
			return "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
					+ "&nbsp;" + getIndividumBirthDateAsString()
					+"<br>"
					+this.messages.getString(nombreType.NJP +"22")
					+ getAutorAndSource(nombreType.NJP);
		default:
			break;
		}
		return interpretationNH;
	}
	
	/**
	 * interpretCroise
	 * @param valueNH1
	 * @param valueNH2
	 * @return
	 */
	public String interpretCroise(){
		int valueNE1 = this.firstPerson.getNombreDExpression();
		int valueNE2 = this.secondPerson.getNombreDExpression();
		return "<b>"+ firstPerson.getFirstNames() +"&nbsp;" + firstPerson.getNames() +"</b>"
		+ this.messages.getString(nombreType.NE +"Title") +"&nbsp;" 
		+"<b>" +valueNE1 +"</b>"
		+"<br>"
		+"<b>"+ secondPerson.getFirstNames() +"&nbsp;" + secondPerson.getNames() +"</b>"
		+ this.messages.getString(nombreType.NE + "Title") +"&nbsp;"
		+"<b>" +valueNE2 +"</b>"
		+"<br>"
		+"<b>" + this.messages.getString("feuilleCaption") +"</b>"
		+"<br>"
		+ getCombinedText(valueNE1, valueNE2)
		+"<br>"
		+ getAutorAndSource(nombreType.NCroise);
		
	}
	public String getAutorAndSource(nombreType type){
		return (this.messages.getString(type.toString() + "Source") 
				+ "&nbsp;"
				+"<b>" 
				+ this.messages.getString(type.toString() +  "Autor")
				+"</b>");
	}
	 /**
	  * 
	  * @param secondValueNE
	  * @return
	  */
	private String getCombinedText(int firstValueNE, int secondValueNE){
		String firstNE = String.valueOf(firstValueNE);
		switch(secondValueNE){
		case 1:
			return this.messages.getString(nombreType.NCroise + firstNE + "_1");
		case 2:
			return this.messages.getString(nombreType.NCroise + firstNE + "_2");
		case 3:
			return this.messages.getString(nombreType.NCroise + firstNE + "_3");
		case 4:
			return this.messages.getString(nombreType.NCroise + firstNE + "_4");
		case 5:
			return this.messages.getString(nombreType.NCroise + firstNE + "_5");
		case 6:
			return this.messages.getString(nombreType.NCroise + firstNE + "_6");
		case 7:
			return this.messages.getString(nombreType.NCroise + firstNE + "_7");
		case 8:
			return this.messages.getString(nombreType.NCroise + firstNE + "_8");
		case 9:
			return this.messages.getString(nombreType.NCroise + firstNE + "_9");
		case 11:
			return this.messages.getString(nombreType.NCroise + firstNE + "_11");
		case 22:
			return this.messages.getString(nombreType.NCroise + firstNE + "_22");
		default:
			break;
		}
		return null;
	}
	/*
	 * 
	 */
	public String interpretSingleResult(int resultId, nombreType resultType){
		if( resultType == null){
			try {
				throw(new Exception("This Methode need the type of the calculated item"));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		String resultString = "<b>"+ getIndividumFirstNames() +"&nbsp;" +getIndividumNames() +"</b>"
				+ "&nbsp;" + getIndividumBirthDateAsString()
				+"<br>";
		switch (resultId) {
		case 1: resultString += this.messages.getString(resultType +"1");
				break;
		case 2: resultString += this.messages.getString(resultType +"2");
				break;
		case 3: resultString += this.messages.getString(resultType +"3");
				break;
		case 4: resultString += this.messages.getString(resultType +"4");
				break;
		case 5: resultString += this.messages.getString(resultType +"5");
				break;
		case 6: resultString += this.messages.getString(resultType +"6");
				break;
		case 7: resultString += this.messages.getString(resultType +"7");
				break;
		case 8: resultString += this.messages.getString(resultType +"8");
				break;
		case 9: resultString += this.messages.getString(resultType +"9");
				break;
		case 11: resultString += this.messages.getString(resultType +"11");
				break;
		case 22: resultString += this.messages.getString(resultType +"22");
				break;
		}
		resultString += "<br>"+ getAutorAndSource(resultType);
		
		return resultString;
	}
	
}
